Imports System.Data.SqlClient

Public Class LoaiChietTinh
    Private sMaLoaiChietTinh As String
    Private sTenLoaiChietTinh As String

    Public Property MaLoaiChietTinh() As String
        Get
            Return sMaLoaiChietTinh
        End Get
        Set(ByVal Value As String)
            sMaLoaiChietTinh = Value
        End Set
    End Property

    Public Property TenLoaiChietTinh() As String
        Get
            Return sTenLoaiChietTinh
        End Get
        Set(ByVal Value As String)
            sTenLoaiChietTinh = Value
        End Set
    End Property

End Class

Public Class LoaiChietTinhF

    Public Function GetAll() As DataTable
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "LoaiChietTinh_GetAll"

        End With

        myDat = New SqlDataAdapter(myCmd)
        myDat.Fill(myDtb)
        Return myDtb
        myCnn.Close()
    End Function

    Public Function GetInThang() As DataTable
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "LoaiChietTinh_GetInThang"

            .Parameters.Add(New SqlClient.SqlParameter("@nam", SqlDbType.Char))
            .Parameters("@nam").Value = Project_Nam

            .Parameters.Add(New SqlClient.SqlParameter("@thang", SqlDbType.Char))
            .Parameters("@thang").Value = Project_Thang

        End With

        myDat = New SqlDataAdapter(myCmd)
        myDat.Fill(myDtb)
        Return myDtb
        myCnn.Close()
    End Function

    Public Function GetWhereMaLoaiChietTinh(ByVal MaloaiChietTinh As String) As DataTable
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "LoaiChietTinh_GetWhereMaLoaiChietTinh"

            .Parameters.Add(New SqlClient.SqlParameter("@maloaichiettinh", SqlDbType.Char))
            .Parameters("@maloaichiettinh").Value = MaloaiChietTinh

        End With

        myDat = New SqlDataAdapter(myCmd)
        myDat.Fill(myDtb)
        Return myDtb
        myCnn.Close()
    End Function

    Public Function ExistsMaLoaiChietTinh(ByVal MaLoaiChietTinh As String) As Boolean
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "LoaiChietTinh_ExistsMaLoaiChietTinh"

            .Parameters.Add(New SqlClient.SqlParameter("@maloaichiettinh", SqlDbType.Char))
            .Parameters("@maloaichiettinh").Value = MaLoaiChietTinh

            .Parameters.Add(New SqlClient.SqlParameter("@return", SqlDbType.Bit)).Direction = ParameterDirection.ReturnValue
            .ExecuteNonQuery()
        End With

        If myCmd.Parameters("@return").Value = 1 Then
            myCnn.Close()
            myCnn.Dispose()
            Return True
        Else
            myCnn.Close()
            myCnn.Dispose()
            Return False
        End If
    End Function

    Public Function Save(ByVal LoaiChietTinh As LoaiChietTinh) As Boolean
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "LoaiChietTinh_Save"

            .Parameters.Add(New SqlClient.SqlParameter("@maloaichiettinh", SqlDbType.Char))
            .Parameters("@maloaichiettinh").Value = LoaiChietTinh.MaLoaiChietTinh

            .Parameters.Add(New SqlClient.SqlParameter("@tenloaichiettinh", SqlDbType.NVarChar))
            .Parameters("@tenloaichiettinh").Value = LoaiChietTinh.TenLoaiChietTinh

            .Parameters.Add(New SqlClient.SqlParameter("@return", SqlDbType.Bit)).Direction = ParameterDirection.ReturnValue
            .ExecuteNonQuery()
        End With

        If myCmd.Parameters("@return").Value = 1 Then
            myCnn.Close()
            myCnn.Dispose()
            Return True
        Else
            myCnn.Close()
            myCnn.Dispose()
            Return False
        End If
    End Function

    Public Function Delete(ByVal MaLoaiChietTinh As String) As Boolean
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "LoaiChietTinh_Delete"

            .Parameters.Add(New SqlClient.SqlParameter("@maloaichiettinh", SqlDbType.Char))
            .Parameters("@maloaichiettinh").Value = MaLoaiChietTinh

            .Parameters.Add(New SqlClient.SqlParameter("@return", SqlDbType.Bit)).Direction = ParameterDirection.ReturnValue
            .ExecuteNonQuery()
        End With

        If myCmd.Parameters("@return").Value = 1 Then
            myCnn.Close()
            myCnn.Dispose()
            Return True
        Else
            myCnn.Close()
            myCnn.Dispose()
            Return False
        End If
    End Function

End Class


Public Class LoaiChietTinhCt
    Private sMaLoaiChietTinh As String
    Private sMa As String
    Private nSldl As Decimal
    Private nSlkh As Decimal

    Public Property MaLoaiChietTinh() As String
        Get
            Return sMaLoaiChietTinh
        End Get
        Set(ByVal Value As String)
            sMaLoaiChietTinh = Value
        End Set
    End Property

    Public Property Ma() As String
        Get
            Return sMa
        End Get
        Set(ByVal Value As String)
            sMa = Value
        End Set
    End Property

    Public Property Sldl() As Decimal
        Get
            Return nSldl
        End Get
        Set(ByVal Value As Decimal)
            nSldl = Value
        End Set
    End Property

    Public Property Slkh() As Decimal
        Get
            Return nSlkh
        End Get
        Set(ByVal Value As Decimal)
            nSlkh = Value
        End Set
    End Property

End Class

Public Class LoaiChietTinhCtF

    Public Function GetWhereMaLoaiChietTinh(ByVal MaLoaiChietTinh As String) As DataTable
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "LoaiChietTinhCt_GetWhereMaLoaiChietTinh"

            .Parameters.Add(New SqlClient.SqlParameter("@maloaichiettinh", SqlDbType.Char))
            .Parameters("@maloaichiettinh").Value = MaLoaiChietTinh

        End With

        myDat = New SqlDataAdapter(myCmd)
        myDat.Fill(myDtb)
        Return myDtb
        myCnn.Close()
    End Function

    Public Function Insert(ByVal LoaiChietTinhCt As LoaiChietTinhCt) As Boolean
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "LoaiChietTinhCt_Insert"

            .Parameters.Add(New SqlClient.SqlParameter("@maloaichiettinh", SqlDbType.Char))
            .Parameters("@maloaichiettinh").Value = LoaiChietTinhCt.MaLoaiChietTinh

            .Parameters.Add(New SqlClient.SqlParameter("@ma", SqlDbType.Char))
            .Parameters("@ma").Value = LoaiChietTinhCt.Ma

            .Parameters.Add(New SqlClient.SqlParameter("@sldl", SqlDbType.Decimal))
            .Parameters("@sldl").Value = LoaiChietTinhCt.Sldl

            .Parameters.Add(New SqlClient.SqlParameter("@slkh", SqlDbType.Decimal))
            .Parameters("@slkh").Value = LoaiChietTinhCt.Slkh
            
            .Parameters.Add(New SqlClient.SqlParameter("@return", SqlDbType.Bit)).Direction = ParameterDirection.ReturnValue
            .ExecuteNonQuery()
        End With

        If myCmd.Parameters("@return").Value = 1 Then
            myCnn.Close()
            myCnn.Dispose()
            Return True
        Else
            myCnn.Close()
            myCnn.Dispose()
            Return False
        End If
    End Function

    Public Function Delete(ByVal MaLoaiChietTinh As String) As Boolean
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "LoaiChietTinhCt_Delete"

            .Parameters.Add(New SqlClient.SqlParameter("@maloaichiettinh", SqlDbType.Char))
            .Parameters("@maloaichiettinh").Value = MaLoaiChietTinh

            .Parameters.Add(New SqlClient.SqlParameter("@return", SqlDbType.Bit)).Direction = ParameterDirection.ReturnValue
            .ExecuteNonQuery()
        End With

        If myCmd.Parameters("@return").Value = 1 Then
            myCnn.Close()
            myCnn.Dispose()
            Return True
        Else
            myCnn.Close()
            myCnn.Dispose()
            Return False
        End If
    End Function

    Public Function ExistsMa(ByVal Ma As Decimal) As Boolean
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "LoaiChietTinhCt_ExistsMa"

            .Parameters.Add(New SqlClient.SqlParameter("@ma", SqlDbType.Char))
            .Parameters("@ma").Value = Ma

            .Parameters.Add(New SqlClient.SqlParameter("@return", SqlDbType.Bit)).Direction = ParameterDirection.ReturnValue
            .ExecuteNonQuery()
        End With

        If myCmd.Parameters("@return").Value = 1 Then
            myCnn.Close()
            myCnn.Dispose()
            Return True
        Else
            myCnn.Close()
            myCnn.Dispose()
            Return False
        End If
    End Function

End Class


